package com.jbm.jbmsupplier.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.weather.myframe.Log;
import com.example.weather.myframe.PopupSelectImage;
import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.activity.address.view.ShowImageViews;
import com.jbm.jbmsupplier.activity.rxjavanet.ModeRxjavaNet;
import com.jbm.jbmsupplier.adapter.Gridviewlayout;
import com.jbm.jbmsupplier.adapter.Gridviewlayouts;
import com.jbm.jbmsupplier.presenters.DispushActivitys;
import com.jbm.jbmsupplier.utlis.ExitActivity;
import com.jbm.jbmsupplier.utlis.PtesonalPrivile;
import com.jbm.jbmsupplier.view.DialogLoading;
import com.jbm.jbmsupplier.view.DoubleButtonDialog;
import com.jbm.jbmsupplier.views.DispushViews;
import com.jbm.jbmsupplier.zp.liaotian.ShowImageView;
import com.jbm.onehome.iface.IOrder;
import com.jbm.onehome.iface.ISellerCtrl;
import com.jbm.onehome.iface.IorderEntity;
import com.jbm.onehome.iface.JobOrderEntity;
import com.jbm.onehome.iface.SellerEntity;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static com.jbm.jbmsupplier.R.id.layout_weixiutupian;


/**
 * Created by 家帮忙 on 2017/4/13.
 */

public class DispushActivity extends AllActivityApp implements DispushViews {
    @InjectView(R.id.teleft)
    TextView teleft;
    @InjectView(R.id.tetitle)
    TextView tetitle;
    @InjectView(R.id.ddbh)
    TextView ddbh;
    @InjectView(R.id.stuti)
    TextView stuti;
    @InjectView(R.id.ddshij)
    TextView ddshij;
    @InjectView(R.id.funr)
    TextView funr;
    @InjectView(R.id.tname)
    TextView tname;
    @InjectView(R.id.dianhua)
    TextView dianhua;
    @InjectView(R.id.dizhi)
    TextView dizhi;
    @InjectView(R.id.fwnrong)
    TextView wcxinxi;
    @InjectView(R.id.baoxiuqi)
    TextView baoxiuqi;
    @InjectView(R.id.wcdingdan)
    Button wcdingdan;
    @InjectView(R.id.zzhidiagndan)
    Button zzhidiagndan;
    @InjectView(R.id.querendigndan)
    Button querendigndan;
    @InjectView(R.id.xianziazhifu)
    Button xianziazhifu;
    @InjectView(R.id.wiujiage)
    TextView wiujiage;
    @InjectView(R.id.sgdbianhao)
    TextView sgdbianhao;
    @InjectView(R.id.gridviewla)
    RecyclerView gridviewla;
    @InjectView(R.id.layout_baoxiutupian)
    LinearLayout layoutBaoxiutupian;
    @InjectView(R.id.gridviewla_weiziu)
    RecyclerView gridviewlaWeiziu;
    @InjectView(layout_weixiutupian)
    LinearLayout layoutWeixiutupian;
    @InjectView(R.id.layout_weixiuneirong)
    LinearLayout layoutWeixiuneirong;
    @InjectView(R.id.layout_weixiujiage)
    LinearLayout layoutWeixiujiage;
    @InjectView(R.id.layout_baoxiuqi)
    LinearLayout layoutBaoxiuqi;
    @InjectView(R.id.shigongdui)
    TextView shigongdui;
    @InjectView(R.id.paidan)
    Button paidan;
    @InjectView(R.id.zhuanjiabangmang)
    Button zhuanjiabangmang;
    @InjectView(R.id.shigongduilayout)
    LinearLayout shigongduilayout;
    @InjectView(R.id.layoutbut)
    LinearLayout layoutbut;
    @InjectView(R.id.gongdanbianhao)
    LinearLayout gongdanbianhao;
    @InjectView(R.id.shoujihao)
    TextView shoujihao;
    @InjectView(R.id.shoujihaolayout)
    LinearLayout shoujihaolayout;
    //    @InjectView(R.id.layout_weixiutupian)
//    LinearLayout layoutWeixiutupian;

    @InjectView(R.id.imfuwuqian)
    ImageView imfuwuqian;
    @InjectView(R.id.imfuwuzhong)
    ImageView imfuwuzhong;
    @InjectView(R.id.imfuwuhou)
    ImageView imfuwuhou;
    @InjectView(R.id.yuejiezhifu)
    Button yuejiezhifu;
    @InjectView(R.id.jjrtname)
    TextView jjrtname;
    @InjectView(R.id.jjrdianhua)
    TextView jjrdianhua;
    @InjectView(R.id.woaiwojiabianhao)
    TextView woaiwojiabianhao;
    @InjectView(R.id.woaiwojiasbianhao)
    LinearLayout woaiwojiasbianhao;
    @InjectView(R.id.layoutdispuipc)
    LinearLayout layoutdispuipc;
    @InjectView(R.id.zhongzhdigndan_static)
    Button zhongzhdigndanStatic;
    @InjectView(R.id.layout_quxiaoqueren)
    LinearLayout layoutQuxiaoqueren;
    @InjectView(R.id.layoutjjrname)
    LinearLayout layoutjjrname;
    @InjectView(R.id.fwnrong)
    TextView fwnrong;
    @InjectView(R.id.clmxi)
    TextView clmxi;
    @InjectView(R.id.fwje)
    TextView fwje;
    @InjectView(R.id.clje)
    TextView clje;
    @InjectView(R.id.layout_cailiaomingxi)
    LinearLayout layout_cailiaomingxi;


    @InjectView(R.id.wowojiadiangdanbianhao)
    LinearLayout wowojiadiangdanbianhao;

    private DispushActivitys dispushActivitys;
    private Gridviewlayout gridviews;
    private IorderEntity orders;
    private String pri;
    private String vis;
    private Gridviewlayouts gridviewss;
    ArrayList<HashMap<String, String>> lipicatatic;//保存维修中状态的图片
    ArrayList<String> lipicastr;//保存维修中状态的图片
    IorderEntity iorderEntitys;

    @Override
    public int setContentView() {
        return R.layout.lz_dispush;
    }

    @Override
    public void initIalizeView() {
        ExitActivity.getInstance().addActivity(this);
        ButterKnife.inject(this);
        lipicatatic = new ArrayList<>();
        lipicastr = new ArrayList<>();
        gridviewla.setLayoutManager(new GridLayoutManager(this, 3));
        gridviewlaWeiziu.setLayoutManager(new GridLayoutManager(this, 3));
        dispushActivitys = new DispushActivitys(this, this);
        tetitle.setText("订单信息");
        dispushActivitys.setInitDate();
        pri = new PtesonalPrivile().getPrson(getApplication());
        initdate();
        dialogLoading = new DialogLoading(this, "加载中...", true);

    }


    JobOrderEntity order;

    private void initdate() {
        if (getIntent().getStringExtra("tag").equals("2")) {
            order = (JobOrderEntity) getIntent().getSerializableExtra("order");
        } else if (getIntent().getStringExtra("tag").equals("1")) {
            orders = (IorderEntity) getIntent().getSerializableExtra("order");
            vis = getIntent().getStringExtra("vis");
        }
        if (order != null) {
            ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<IorderEntity>() {
                @Override
                public void call(Subscriber<? super IorderEntity> subscriber) {
                    subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().LoadOrderInfo(order.getOrderId()));
                }
            })).subscribe(new Observer<IorderEntity>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(IorderEntity iorderEntity) {
                    if (iorderEntity.m_code == 200) {
                        iorderEntitys = iorderEntity;
                        if (iorderEntity.getStatus().equals("new")) {
                            querendigndan.setVisibility(VISIBLE);
//                            layoutQuxiaoqueren.setVisibility(VISIBLE);
                            zhongzhdigndanStatic.setVisibility(GONE);
                            layoutdispuipc.setVisibility(GONE);
                            stuti.setText("新订单");
                        } else if (iorderEntity.getStatus().equals("confirm")) {
                            zzhidiagndan.setVisibility(VISIBLE);
                            wcdingdan.setVisibility(VISIBLE);
                            stuti.setText("作业中");
                        } else if (iorderEntity.getStatus().equals("submit")) {
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            stuti.setText("待付款");
                        }
                        if (iorderEntity.getStatus().equals("break")) {
                            stuti.setText("已作废");
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                        }
                        if (iorderEntity.getStatus().equals("revoke")) {
                            stuti.setText("已作废");
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            paidan.setVisibility(GONE);
                            zhuanjiabangmang.setVisibility(GONE);

                        }

                        if (iorderEntity.getStatus().equals("payed")) {
                            xianziazhifu.setVisibility(GONE);

                        }


                        if (iorderEntity.getOrderCode() != null) {
                            ddbh.setText("" + iorderEntity.getOrderCode());
                        }
                        if (iorderEntity.getCreateDate() != null) {
                            ddshij.setText(iorderEntity.getCreateDate() + "");
                        }

                        if (iorderEntity.getContacts() != null) {
                            tname.setText(iorderEntity.getContacts() + "");
                        }
                        if (iorderEntity.getMobile() != null) {
                            dianhua.setText(iorderEntity.getMobile());
                        }
                        if (iorderEntity.getGiText() != null) {
                            dizhi.setText(iorderEntity.getGiText() + "");
                        }
                        if (iorderEntity.getOrdattachmentlist() != null) {
                            dispushActivitys.showDingDanPic(iorderEntity.getOrdattachmentlist());
                        }
                        if (iorderEntity.getItemDesc() != null) {
                            funr.setText(iorderEntity.getItemDesc());
                        }
                        if (iorderEntity.getGiType().equals("t")) {
                            if (iorderEntity.getStatus().equals("completed")) {
                                xianziazhifu.setVisibility(VISIBLE);

                            }
                            if (iorderEntity.getAmount() != null) {//金额
                                layoutWeixiujiage.setVisibility(VISIBLE);
                                wiujiage.setText("" + iorderEntity.getAmount().intValue());

                            }
                        } else if (iorderEntity.getGiType().equals("j")) {
                            layoutjjrname.setVisibility(VISIBLE);
                            wowojiadiangdanbianhao.setVisibility(VISIBLE);
                            if (iorderEntity.getExtOrderCode() != null) {
                                woaiwojiabianhao.setText(iorderEntity.getExtOrderCode() + "");
                            }
                            if (iorderEntity.getProxy() != null) {
                                jjrtname.setText(iorderEntity.getProxy() + "");
                            }
                            if (iorderEntity.getProxyMobile() != null) {
                                jjrdianhua.setText(iorderEntity.getProxyMobile() + "");
                            }
                            if (!iorderEntity.getStatus().equals("new") && !iorderEntity.getStatus().equals("confirm")) {

                                woaiwojiasbianhao.setVisibility(VISIBLE);
                                layout_cailiaomingxi.setVisibility(VISIBLE);
                                if (iorderEntity.getAmount() != null) {//金额
                                    layoutWeixiujiage.setVisibility(VISIBLE);
                                    wiujiage.setText("" + iorderEntity.getAmount().intValue());
                                }


//                             //服务描述
//                            if (iorderEntity.getjubsum() != null) {
//                                jjrtname.setText(iorderEntity.getItemDesc() + "");
//                            }
                                //材料描述
                                if (iorderEntity.getJoborderlist() != null) {
                                    if (iorderEntity.getJoborderlist().get(0).getItemSum() != null) {
                                        clmxi.setText(iorderEntity.getJoborderlist().get(0).getItemSum() + "");
                                    } else {
                                        clmxi.setText("无");
                                    }
                                }

                                //服务金额
                                if (iorderEntity.getJobAmount() != null) {
                                    fwje.setText(iorderEntity.getJobAmount().intValue() + "");
                                } else {
                                    fwje.setText("0");
                                }
                                //材料金额
                                if (iorderEntity.getItemAmount() != null) {
                                    clje.setText(iorderEntity.getItemAmount().intValue() + "");
                                } else {
                                    clje.setText("0");
                                }


                            }

                        }

                        ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<JobOrderEntity>() {
                            @Override
                            public void call(Subscriber<? super JobOrderEntity> subscriber) {
                                subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().LoadJOrderN(order.getJorderId()));

                            }
                        })).subscribe(new Observer<JobOrderEntity>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(JobOrderEntity iorderEntity) {
                                if (iorderEntity.m_code == 200) {
                                    if (iorderEntity != null) {
                                        if (iorderEntity.getStatus().equals("payed")) {
                                            wcdingdan.setVisibility(GONE);
                                            zzhidiagndan.setVisibility(GONE);
                                            querendigndan.setVisibility(GONE);
                                            xianziazhifu.setVisibility(GONE);
                                            paidan.setVisibility(GONE);
                                            zhuanjiabangmang.setVisibility(GONE);
                                            stuti.setText("已付款");
                                        }
                                        if (iorderEntity.getStatus().equals("comment")) {
                                            stuti.setText("已评价");
                                            wcdingdan.setVisibility(GONE);
                                            zzhidiagndan.setVisibility(GONE);
                                            querendigndan.setVisibility(GONE);
                                            xianziazhifu.setVisibility(GONE);
                                            paidan.setVisibility(GONE);
                                            zhuanjiabangmang.setVisibility(GONE);
                                        }
                                        //工单code
                                        if (iorderEntity.getJorderCode() != null) {
                                            gongdanbianhao.setVisibility(VISIBLE);
                                            sgdbianhao.setText("" + iorderEntity.getJorderCode());
                                        }
                                        //施工队
                                        if (iorderEntity.getSeller().getName() != null) {
                                            shigongduilayout.setVisibility(VISIBLE);
                                            shigongdui.setText(iorderEntity.getSeller().getName());

                                        }
                                        //施工队
                                        if (iorderEntity.getSeller().getMobile() != null) {
                                            shoujihaolayout.setVisibility(VISIBLE);
                                            shoujihao.setText(iorderEntity.getSeller().getMobile());

                                        }
                                        //维修内容
                                        if (iorderEntity.getJobSum() != null) {
                                            layoutWeixiuneirong.setVisibility(VISIBLE);
                                            wcxinxi.setText(iorderEntity.getJobSum());
                                        }
                                        //保修期
                                        if (iorderEntity.getGuaranteeDate() != null) {
                                            layoutBaoxiuqi.setVisibility(VISIBLE);
                                            baoxiuqi.setText("" + iorderEntity.getGuaranteeDate());
                                        }


                                        if (iorderEntity.getJordAttachmentList() != null) {
                                            dispushActivitys.showGongDanPic(iorderEntity.getJordAttachmentList());
                                        }
                                    }
                                }

                            }
                        });


                    }

                }
            });
        }

        if (orders != null) {
            ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<IorderEntity>() {
                @Override
                public void call(Subscriber<? super IorderEntity> subscriber) {
                    subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().LoadOrderInfo(orders.getOrderId()));

                }
            })).subscribe(new Observer<IorderEntity>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(IorderEntity iorderEntity) {
                    if (iorderEntity.m_code == 200) {
                        if (iorderEntity.getStatus().equals("temp")) {
                            if (vis.equals("1")) {
                                paidan.setVisibility(GONE);
                                zhuanjiabangmang.setVisibility(GONE);
                            } else if (vis.equals("2")) {
                                paidan.setVisibility(VISIBLE);
                                zhuanjiabangmang.setVisibility(VISIBLE);
                            }
                            stuti.setText("新订单");
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            layoutdispuipc.setVisibility(GONE);
                        } else if (iorderEntity.getStatus().equals("new")) {
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            paidan.setVisibility(GONE);
                            zhuanjiabangmang.setVisibility(GONE);
                            stuti.setText("待确认");
                        } else if (iorderEntity.getStatus().equals("confirm")) {
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            paidan.setVisibility(GONE);
                            zhuanjiabangmang.setVisibility(GONE);
                            stuti.setText("作业中");
                        } else if (iorderEntity.getStatus().equals("submit")) {
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            paidan.setVisibility(GONE);
                            zhuanjiabangmang.setVisibility(GONE);
                            dispushActivitys.getShowJine(orders.getOrderId());
                            stuti.setText("待付款");
                        }
//                        else if (iorderEntity.getStatus().equals("break")) {
//                            stuti.setText("已作废");
//                            wcdingdan.setVisibility(GONE);
//                            zzhidiagndan.setVisibility(GONE);
//                            querendigndan.setVisibility(GONE);
//                            xianziazhifu.setVisibility(GONE);
//                            paidan.setVisibility(GONE);
//                            zhuanjiabangmang.setVisibility(GONE);
//                        }
                        else if (iorderEntity.getStatus().equals("revoke")) {
                            stuti.setText("已作废");
                            wcdingdan.setVisibility(GONE);
                            zzhidiagndan.setVisibility(GONE);
                            querendigndan.setVisibility(GONE);
                            xianziazhifu.setVisibility(GONE);
                            paidan.setVisibility(GONE);
                            zhuanjiabangmang.setVisibility(GONE);

                        }
                        if (iorderEntity.getOrderCode() != null) {
                            ddbh.setText("" + iorderEntity.getOrderCode());
                        }
                        if (iorderEntity.getCreateDate() != null) {
                            ddshij.setText(iorderEntity.getCreateDate() + "");
                        }

                        if (iorderEntity.getContacts() != null) {
                            tname.setText(iorderEntity.getContacts() + "");
                        }
                        if (iorderEntity.getMobile() != null) {
                            dianhua.setText(iorderEntity.getMobile());
                        }
                        if (iorderEntity.getGiText() != null) {
                            dizhi.setText(iorderEntity.getGiText() + "");
                        }
                        if (iorderEntity.getItemDesc() != null) {
                            funr.setText(iorderEntity.getItemDesc());
                        }
                        if (iorderEntity.getGiType().equals("t")) {

                            if (iorderEntity.getAmount() != null) {//金额
                                layoutWeixiujiage.setVisibility(VISIBLE);
                                wiujiage.setText("" + iorderEntity.getAmount().intValue());

                            }
                        } else if (iorderEntity.getGiType().equals("j")) {
                            layoutjjrname.setVisibility(VISIBLE);
                            wowojiadiangdanbianhao.setVisibility(VISIBLE);
                            if (iorderEntity.getExtOrderCode() != null) {
                                woaiwojiabianhao.setText(iorderEntity.getExtOrderCode() + "");
                            }
                            if (iorderEntity.getProxy() != null) {
                                jjrtname.setText(iorderEntity.getProxy() + "");
                            }
                            if (iorderEntity.getProxyMobile() != null) {
                                jjrdianhua.setText(iorderEntity.getProxyMobile() + "");
                            }
                            if (!iorderEntity.getStatus().equals("new") && !iorderEntity.getStatus().equals("confirm")) {
                                woaiwojiasbianhao.setVisibility(VISIBLE);
                                layout_cailiaomingxi.setVisibility(VISIBLE);
                                if (iorderEntity.getAmount() != null) {//金额
                                    layoutWeixiujiage.setVisibility(VISIBLE);
                                    wiujiage.setText("" + iorderEntity.getAmount().intValue());
                                }

//                             //服务描述
//                            if (iorderEntity.getjubsum() != null) {
//                                jjrtname.setText(iorderEntity.getItemDesc() + "");
//                            }
                                if (iorderEntity.getJoborderlist() != null) {

                                    //材料描述
                                    if (iorderEntity.getJoborderlist().get(0).getItemSum() != null) {
                                        clmxi.setText(iorderEntity.getJoborderlist().get(0).getItemSum() + "");
                                    } else {
                                        clmxi.setText("无");
                                    }
                                }
                                //服务金额
                                if (iorderEntity.getJobAmount() != null) {
                                    fwje.setText(iorderEntity.getJobAmount().intValue() + "");
                                } else {
                                    fwje.setText("0");
                                }
                                //材料金额
                                if (iorderEntity.getItemAmount() != null) {
                                    clje.setText(iorderEntity.getItemAmount().intValue() + "");
                                } else {
                                    clje.setText("0");
                                }


                            }

                        }

                        if (iorderEntity.getOrdattachmentlist() != null) {
                            dispushActivitys.showDingDanPic(iorderEntity.getOrdattachmentlist());
                        }


                        if (iorderEntity.getJoborderlist() != null) {
                            if (iorderEntity.getJoborderlist().get(0).getStatus().equals("payed")) {
                                wcdingdan.setVisibility(GONE);
                                zzhidiagndan.setVisibility(GONE);
                                querendigndan.setVisibility(GONE);
                                xianziazhifu.setVisibility(GONE);
                                paidan.setVisibility(GONE);
                                zhuanjiabangmang.setVisibility(GONE);
                                stuti.setText("已付款");
                            }
                            if (iorderEntity.getJoborderlist().get(0).getStatus().equals("comment")) {
                                stuti.setText("已评价");
                                wcdingdan.setVisibility(GONE);
                                zzhidiagndan.setVisibility(GONE);
                                querendigndan.setVisibility(GONE);
                                xianziazhifu.setVisibility(GONE);
                                paidan.setVisibility(GONE);
                                zhuanjiabangmang.setVisibility(GONE);
                            }
                            if (iorderEntity.getJoborderlist().get(0).getJorderCode() != null) {//工单code
                                gongdanbianhao.setVisibility(VISIBLE);
                                sgdbianhao.setText("" + iorderEntity.getJoborderlist().get(0).getJorderCode());
                            }
                            if (iorderEntity.getJoborderlist().get(0).getSeller().getName() != null) {//施工队
                                shigongduilayout.setVisibility(VISIBLE);
                                shigongdui.setText(iorderEntity.getJoborderlist().get(0).getSeller().getName());

                            }
                            if (iorderEntity.getJoborderlist().get(0).getSeller().getMobile() != null) {//施工队
                                shoujihaolayout.setVisibility(VISIBLE);
                                shoujihao.setText(iorderEntity.getJoborderlist().get(0).getSeller().getMobile());

                            }
                            if (iorderEntity.getJoborderlist().get(0).getJobSum() != null) {//维修内容
                                layoutWeixiuneirong.setVisibility(VISIBLE);
                                wcxinxi.setText(iorderEntity.getJoborderlist().get(0).getJobSum());
                            }
                            if (iorderEntity.getJoborderlist().get(0).getGuaranteeDate() != null) {//保修期
                                layoutBaoxiuqi.setVisibility(VISIBLE);
                                baoxiuqi.setText("" + iorderEntity.getJoborderlist().get(0).getGuaranteeDate());
                            }
                            if (iorderEntity.getJoborderlist().get(0).getMemo() != null) {//金额
                                layoutWeixiujiage.setVisibility(VISIBLE);
                                wiujiage.setText("" + iorderEntity.getJoborderlist().get(0).getMemo());
                            }

                            if (iorderEntity.getJoborderlist().get(0).getJordAttachmentList() != null) {
                                dispushActivitys.showGongDanPic(iorderEntity.getJoborderlist().get(0).getJordAttachmentList());
                            }
                        }
                    } else {

                    }
                }
            });


        }


    }

    private DialogLoading dialogLoading;
    int i = 0;//标记点击图片是获取图片还是放大

    @OnClick({R.id.teleft, R.id.dianhua, R.id.wcdingdan, R.id.zzhidiagndan, R.id.querendigndan, R.id.xianziazhifu, R.id.paidan, R.id.zhuanjiabangmang, R.id.imfuwuqian, R.id.imfuwuzhong, R.id.imfuwuhou, R.id.yuejiezhifu, R.id.zhongzhdigndan_static})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.teleft:
                finish();
                break;
            case R.id.dianhua:
                Intent intentPhone = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + order.getIorderEntity().getMobile()));
                startActivity(intentPhone);
                break;
            case R.id.wcdingdan:
                Intent intent = new Intent(this, AccomPlishActivity.class);
                intent.putExtra("orid", order.getJorderId());
                intent.putExtra("gi_type", iorderEntitys.getGiType());
                startActivity(intent);
                finish();
                break;
            case R.id.zzhidiagndan:
                Intent intents = new Intent(this, TerMinorActivity.class);
                intents.putExtra("orid", order.getJorderId());
                intents.putExtra("tag", "1");
                startActivity(intents);
                finish();
                break;
            case R.id.zhongzhdigndan_static:
                Intent qintent = new Intent(this, TerMinorActivity.class);
                qintent.putExtra("tag", "2");
                qintent.putExtra("orid", order.getJorderId());
                startActivity(qintent);
                finish();
                break;
            case R.id.querendigndan:
                dispushActivitys.setQuedingOrder(order.getJorderId());
                break;
            case R.id.xianziazhifu:
                dispushActivitys.setXianxiaOrder(order.getIorderEntity().getOrderId());
                break;
            case R.id.yuejiezhifu:

                break;
            case R.id.paidan:
                if (pri != null) {
                    if (pri.contains("工单分配") || pri.contains("经理") || pri.contains("副经理")) {
                        getGongDanFenPei();
                    } else {
                        Toast.makeText(this, "您没有对应权限", Toast.LENGTH_SHORT).show();

                    }
                }
                break;
            case R.id.zhuanjiabangmang:
                if (pri != null) {
                    if (pri.contains("工单分配") || pri.contains("经理") || pri.contains("副经理")) {
                        final DoubleButtonDialog dialog = new DoubleButtonDialog(DispushActivity.this, "确定派单家帮忙");
                        dialog.setNoText("取消");
                        dialog.setTetle_message("");
                        dialog.setisVisibilitymess();
                        dialog.getokbtn().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {//确定
                                dialogLoading.show();
                                ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<IOrder>() {
                                    @Override
                                    public void call(Subscriber<? super IOrder> subscriber) {
                                        subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().CreateOrder(orders.getOrderId()));
                                    }
                                })).subscribe(new Observer<IOrder>() {
                                    @Override
                                    public void onCompleted() {

                                    }

                                    @Override
                                    public void onError(Throwable e) {

                                    }

                                    @Override
                                    public void onNext(IOrder iOrder) {
                                        if (iOrder.m_code == 200) {
                                            Log.e("成功");

                                            setResult(RESULT_OK);
                                            finish();
                                            if (dialogLoading != null) {
                                                dialogLoading.dismiss();
                                            }
                                        } else {
                                            hint(iOrder.m_info);
                                        }

                                    }
                                });
                                dialog.dismiss();
                            }
                        });
                        dialog.getnobtn().setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });

                    } else {
                        Toast.makeText(this, "您没有对应权限", Toast.LENGTH_SHORT).show();

                    }
                }
                break;
            case R.id.imfuwuqian:
                if (order != null) {
                    if (order.getStatus().equals("new"))
                        return;
                    getDisush(100, 1);
                }
                break;
            case R.id.imfuwuzhong:
                if (order != null) {
                    if (order.getStatus().equals("new"))
                        return;
                    getDisush(200, 2);
                }
                break;
            case R.id.imfuwuhou:
                if (order != null) {
                    if (order.getStatus().equals("new"))
                        return;
                    getDisush(300, 3);
                }
                break;
            default:

        }
    }


    @Override
    public void setSucced(DialogLoading dialogLoading, int tag) {//成功
        if (dialogLoading != null) {
            dialogLoading.dismiss();
        }
        if (tag == 1) {
            sendBroadcast(new Intent("Isorder").putExtra("name", "1"));
            finish();
        } else if (tag == 3) {
            sendBroadcast(new Intent("Isorder").putExtra("name", "3"));
            finish();
        }

    }

    @Override
    public void setEerror(String err, DialogLoading dialogLoading) {//失败
        if (dialogLoading != null) {
            dialogLoading.dismiss();
        }
        if (!err.equals("")) {
            hint(err);
        }
    }

    @Override
    public void setWeiXiuAmout(String name) {//维修价格
        wiujiage.setText("" + name);
    }

    /**
     * 暂时没用
     *
     * @param lipic
     * @param lipics
     */
    @Override
    public void setOrderData(ArrayList<String> lipic, ArrayList<HashMap<String, String>> lipics) {
        if (lipics.size() > 0) {
            layoutBaoxiutupian.setVisibility(VISIBLE);
            gridviews = new Gridviewlayout(DispushActivity.this, lipics);
            gridviewla.setAdapter(gridviews);
            gridviews.notifyDataSetChanged();
//            initOnclick(lipic);
        }
    }

    /**
     * 设置订单图片
     * 施工段 和 管理端 获取图片
     * 都在同一个接口返回
     *
     * @param lipic
     * @param lipics
     */
    @Override
    public void setOrderDatas(ArrayList<String> lipic, ArrayList<HashMap<String, String>> lipics) {
        if (lipics.size() > 0) {
            layoutBaoxiutupian.setVisibility(VISIBLE);
            gridviews = new Gridviewlayout(DispushActivity.this, lipics);
            gridviewla.setAdapter(gridviews);
            gridviews.notifyDataSetChanged();
//            initOnclick(lipic);
        }
    }

    /**
     * 设置工单图片
     * 施工段 和 管理端 获取图片
     * 都在同一个接口返回
     *
     * @param lipic
     * @param lipics
     */
    @Override
    public void setjOrderData(ArrayList<String> lipic, ArrayList<HashMap<String, String>> lipics) {
        if (lipics.size() > 0) {
            //如果图片不为空就从新负值
            layoutWeixiutupian.setVisibility(VISIBLE);
            gridviewss = new Gridviewlayouts(DispushActivity.this, lipics);
            gridviewlaWeiziu.setAdapter(gridviewss);
            gridviewss.notifyDataSetChanged();

            for (int i = 0; i < lipics.size(); i++) {
                if (!lipics.get(i).get("memo").equals("确认单")) {
                    lipicatatic = lipics;
                }
                if (lipics.get(i).get("memo").equals("服务前")) {
                    Picasso.with(DispushActivity.this).load(lipics.get(i).get("pic")).resize(135, 135).into(imfuwuqian);
                }
                if (lipics.get(i).get("memo").equals("服务中")) {
                    Picasso.with(DispushActivity.this).load(lipics.get(i).get("pic")).resize(135, 135).into(imfuwuzhong);
                }
                if (lipics.get(i).get("memo").equals("服务后")) {
                    Picasso.with(DispushActivity.this).load(lipics.get(i).get("pic")).resize(135, 135).into(imfuwuhou);
                }
            }


//            initOnclicks(lipic);
        }
    }

    File file, file1, file2;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case 100:
                file = (File) data.getSerializableExtra("file");
                HashMap<String, String> has = new HashMap<>();
                Picasso.with(DispushActivity.this).load(new File(file.getPath())).resize(135, 135).into(imfuwuqian);
                has.put("pic", file.getAbsolutePath());
                has.put("type", "1");
                has.put("memo", "服务前");
                lipicatatic.add(has);
                dispushActivitys.ShangChuanGDTupian(order.getJorderId(), "服务前", file);
                break;
            case 200:
                HashMap<String, String> has1 = new HashMap<>();
                file1 = (File) data.getSerializableExtra("file");
                has1.put("pic", file1.getAbsolutePath());
                has1.put("type", "2");
                has1.put("memo", "服务中");
                lipicatatic.add(has1);
                Picasso.with(DispushActivity.this).load(new File(file1.getPath())).resize(135, 135).into(imfuwuzhong);
                dispushActivitys.ShangChuanGDTupian(order.getJorderId(), "服务中", file1);
                break;
            case 300:
                HashMap<String, String> has2 = new HashMap<>();
                file2 = (File) data.getSerializableExtra("file");
                has2.put("pic", file2.getAbsolutePath());
                has2.put("type", "3");
                has2.put("memo", "服务后");
                lipicatatic.add(has2);
                Picasso.with(DispushActivity.this).load(new File(file2.getPath())).resize(135, 135).into(imfuwuhou);
                dispushActivitys.ShangChuanGDTupian(order.getJorderId(), "服务后", file2);
                break;
        }


    }

    private void initOnclick(final ArrayList<String> lipic) {
//        gridviewla.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//              HashMap<String,String>  lis= (HashMap<String, String>) parent.getAdapter().getItem(position);
//                         if (lis.get("type").equals("pic")){
//               Intent intent = new Intent(DispushActivity.this, ImagePagerActivity.class);
//                // 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
//                intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, lipic);
//                intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 0);
//                startActivity(intent);
//                             }else if (lis.get("type").equals("audio")){
//                       playMusic(lis.get("pic"));
//                    }
//            }
//        });
    }

    private void initOnclicks(final ArrayList<String> lipic) {
//        gridviewlaWeiziu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                HashMap<String,String>  lis= (HashMap<String, String>) parent.getAdapter().getItem(position);
//                if (lis.get("type").equals("pic")){
//                    Intent intent = new Intent(DispushActivity.this, ImagePagerActivity.class);
//                    // 图片url,为了演示这里使用常量，一般从数据库中或网络中获取
//                    intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, lipic);
//                    intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 0);
//                    startActivity(intent);
//                }else if (lis.get("type").equals("audio")){
//                    playMusic(lis.get("pic"));
//                }
//            }
//        });
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }

    /**
     * 上传施工状态图片
     */
    public void getGongDanFenPei() {
        final AlertDialog al = new AlertDialog.Builder(DispushActivity.this, R.style.dialog).create();
//        al.setCancelable(false);
        View view = View.inflate(DispushActivity.this, R.layout.fenpeidingdan, null);
        final ListView listgongdan = (ListView) view.findViewById(R.id.listviewgogndan);
        final TextView tetitle = (TextView) view.findViewById(R.id.tetitle);
        tetitle.setVisibility(VISIBLE);
        al.setView(view);
        al.show();
        ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<SellerEntity>() {
            @Override
            public void call(Subscriber<? super SellerEntity> subscriber) {
                subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().getMSeller());
            }
        })).subscribe(new Observer<SellerEntity>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(final SellerEntity sellerEntity) {
                if (sellerEntity.m_code == 200) {
                    ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<ISellerCtrl>() {
                        @Override
                        public void call(Subscriber<? super ISellerCtrl> subscriber) {
                            subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().GetSubSellerList(sellerEntity.getSellerId(), true));
                        }
                    })).subscribe(new Observer<ISellerCtrl>() {
                        @Override
                        public void onCompleted() {

                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onNext(ISellerCtrl sellerEntity) {
                            if (sellerEntity.m_code == 200) {
                                ArrayList<SellerEntity> arlist = new ArrayList<SellerEntity>();
                                arlist.addAll(sellerEntity.businessEntityList);
                                listgongdan.setAdapter(new MyAdapterOrder(arlist, DispushActivity.this));
                            } else {
                                hint(sellerEntity.m_info);
                            }


                        }
                    });
                } else {
                    hint(sellerEntity.m_info);
                }
            }
        });

        listgongdan.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final SellerEntity se = (SellerEntity) parent.getAdapter().getItem(position);
                final DoubleButtonDialog dialog = new DoubleButtonDialog(DispushActivity.this, "确定派单给" + se.getName());
                dialog.setNoText("取消");
                dialog.setTetle_message("");
                dialog.setisVisibilitymess();
                dialog.getokbtn().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {//确定
                        dialogLoading.show();
                        ModeRxjavaNet.Companion.getInstantMode().objects(Observable.create(new Observable.OnSubscribe<IOrder>() {
                            @Override
                            public void call(Subscriber<? super IOrder> subscriber) {
                                subscriber.onNext(ModeRxjavaNet.Companion.getInstantMode().getOhInter().CreateJobOrder(orders.getOrderId(), se.getSellerId()));
                            }
                        })).subscribe(new Observer<IOrder>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(IOrder iOrder) {
                                if (iOrder.m_code == 200) {
                                    Log.e("成功");
                                    al.dismiss();
                                    setResult(RESULT_OK);
                                    finish();
                                    if (dialogLoading != null) {
                                        dialogLoading.dismiss();
                                    }
                                } else {
                                    al.dismiss();
                                    hint(iOrder.m_info);
                                }

                            }
                        });
                        dialog.dismiss();
                    }
                });
                dialog.getnobtn().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        dialog.dismiss();
                    }
                });


            }
        });


    }


    static class MyAdapterOrder extends BaseAdapter {
        ArrayList<SellerEntity> arlist;
        Context context;

        public MyAdapterOrder(ArrayList<SellerEntity> arlist, Context context) {
            this.arlist = arlist;
            this.context = context;
        }

        @Override
        public int getCount() {
            return arlist.size();
        }

        @Override
        public Object getItem(int position) {
            return arlist.get(position);
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if (convertView == null) {
                convertView = View.inflate(context, R.layout.fenpeidingdan, null);
            }
            ListView listviewgogndan = (ListView) convertView.findViewById(R.id.listviewgogndan);
            listviewgogndan.setVisibility(GONE);
            TextView te = (TextView) convertView.findViewById(R.id.teviewfenpeigongdan);
            te.setVisibility(View.VISIBLE);
            te.setText("姓名:" + arlist.get(position).getName() + "\n" + "手机号:" + arlist.get(position).getMobile());
            return convertView;
        }
    }


    /**
     * 获取图片
     */
    public void getDisush(int tag, int butt) {
        if (lipicatatic != null) {
            if (lipicatatic.size() <= 0) {
                Intent intent = new Intent(DispushActivity.this, PopupSelectImage.class);
                startActivityForResult(intent, tag);
                return;
            }
            if (butt == 1) {
                for (int j = 0; j < lipicatatic.size(); j++) {
                    lipicastr.add(lipicatatic.get(j).get("memo"));
                    if (!lipicatatic.get(j).get("pic").equals("")) {
                        if (lipicatatic.get(j).get("type").equals("1")) {
                            startActivity(new Intent(DispushActivity.this, ShowImageView.class).putExtra("image", lipicatatic.get(j).get("pic")));
                        } else {
                            if (lipicatatic.get(j).get("memo").equals("服务前")) {
                                startActivity(new Intent(DispushActivity.this, ShowImageViews.class).putExtra("image", lipicatatic.get(j).get("pic")));
                            }
                        }
                    }
                }
                if (!lipicastr.toString().contains("服务前")) {
                    Intent intent = new Intent(DispushActivity.this, PopupSelectImage.class);
                    startActivityForResult(intent, tag);
                }
            } else if (butt == 2) {
                for (int j = 0; j < lipicatatic.size(); j++) {
                    lipicastr.add(lipicatatic.get(j).get("memo"));
                    if (!lipicatatic.get(j).get("pic").equals("")) {
                        if (lipicatatic.get(j).get("type").equals("2")) {
                            startActivity(new Intent(DispushActivity.this, ShowImageView.class).putExtra("image", lipicatatic.get(j).get("pic")));
                        } else {
                            if (lipicatatic.get(j).get("memo").equals("服务中")) {
                                startActivity(new Intent(DispushActivity.this, ShowImageViews.class).putExtra("image", lipicatatic.get(j).get("pic")));
                            }
                        }
                    }
                }
                if (!lipicastr.toString().contains("服务中")) {
                    Intent intent = new Intent(DispushActivity.this, PopupSelectImage.class);
                    startActivityForResult(intent, tag);
                }
            } else if (butt == 3) {
                for (int j = 0; j < lipicatatic.size(); j++) {
                    lipicastr.add(lipicatatic.get(j).get("memo"));
                    if (!lipicatatic.get(j).get("pic").equals("")) {
                        if (lipicatatic.get(j).get("type").equals("3")) {
                            startActivity(new Intent(DispushActivity.this, ShowImageView.class).putExtra("image", lipicatatic.get(j).get("pic")));
                        } else {
                            if (lipicatatic.get(j).get("memo").equals("服务后")) {
                                startActivity(new Intent(DispushActivity.this, ShowImageViews.class).putExtra("image", lipicatatic.get(j).get("pic")));
                            }
                        }
                    }
                }
                if (!lipicastr.toString().contains("服务后")) {
                    Intent intent = new Intent(DispushActivity.this, PopupSelectImage.class);
                    startActivityForResult(intent, tag);
                }
            }


        } else {
            Intent intent = new Intent(DispushActivity.this, PopupSelectImage.class);
            startActivityForResult(intent, tag);
        }


    }


}
